<?php
/**
 * Controller for news
 *
 * @author NguyenVanTien
 */
class NewsController extends Zend_Controller_Action {
    
    /**
     * Instance model new with default value is null
     * @var string $_modelNews 
     */
    protected $_modelNews = null;
    
    /**
     * Instance class controller and set $_modelNews is Application_Model_News
     * @author Tien Nguyen
     */
    public function init(){
        parent::init();
        $this->_modelNews = new Application_Model_News();
    }


    /**
     * Get list last news 
     * @author Tien Nguyen
     */
    public function showListLastNewsAction(){
        $numberRowPerPage = $this->_request->getParam('number-row-per-page', 
                Zend_Registry::get('config')->rows_per_one_page);
        
        //Get list news last
        $selectNews = $this->_modelNews->getListLastNews();
        
        //Paging
        $paginator = Zend_Paginator::factory($selectNews);       
        //Get config for number row in page
        $paginator->setItemCountPerPage($numberRowPerPage);
        $paginator->setPageRange(Zend_Registry::get('config')->number_page_in_paging);
        
        //Set view 
        $this->view->listLastNews = $paginator;
    }
    
    public function newsDetailAction(){
        $newsId = $this->_request->getParam('news-id');
        
        $modelNews = new Application_Model_News();
        $news = $modelNews->getNews($newsId);
        
        $this->view->news = $news;
    }
}